﻿using System;
using System.Linq.Expressions;
using ShopSpace.Infrastructure.Data;

namespace ShopSpace.Core.Repositories.Impl
{
	internal class RepositoryBase<T> : IRepository<T>
		where T: Entity
	{
		public IGenericDAO GenericDAO
		{
			get;
			set;
		}

		public virtual void Add(T target, string addedBy)
		{
			target.AuditAdd(addedBy);
			this.GenericDAO.Save<T>(target);
		}

		public System.Linq.IQueryable<T> AsQueryable()
		{
			return this.GenericDAO.AsQueryable<T>();
		}

		public virtual void Delete(T target, string deletedBy)
		{
			this.GenericDAO.Delete<T>(target);
		}

		public virtual T Get(int id)
		{
			return this.GenericDAO.Find<T>(id);
		}

		public virtual void Update(T target, string updatedBy)
		{
			target.AuditUpdate(updatedBy);
			this.GenericDAO.Save<T>(target);
		}
	}
}
